package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.base.BaseActivity;
import com.sctvcloud.bazhong.base.BaseFragment;
import com.sctvcloud.bazhong.ui.adapter.holder.BaseAbsHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.GovBannerHolder;
import com.sctvcloud.bazhong.ui.adapter.holder.GovDetailHolder;
import com.sctvcloud.bazhong.ui.util.IListShowData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/26 0026.
 */

public class GovAdapter extends BaseHolderAbsAdapter<IListShowData, BaseAbsHolder<IListShowData>> implements OnItemInternalClick {
    public static final int VIEWTYPE_BANNER = 1;//轮播图
    public static final int VIEWTYPE_NEWS = 6; //新闻item

    private OnItemInternalClick onItemInternalClick;
    private BaseActivity activity;
    private BaseFragment fragment;
    private ArrayList<Pair<String, String>> pairs;

    public GovAdapter(Context context,List list) {
        super(context, list);
    }

    public void setActivity(BaseActivity activity) {
        this.activity = activity;
    }

    public void setFragment(BaseFragment fragment) {
        this.fragment = fragment;
    }

    public void setPairs(ArrayList<Pair<String, String>> pairs) {
        this.pairs = pairs;
    }

    @Override
    public BaseAbsHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {

        BaseAbsHolder bah = null;
        View v = null;
        switch (viewType + 1) {
            case VIEWTYPE_BANNER://轮播图
                v = LayoutInflater.from(context).inflate(R.layout.item_gov_banner, parent, false);
                 bah = new GovBannerHolder(context, v);
                break;
            case VIEWTYPE_NEWS:
                v = LayoutInflater.from(context).inflate(R.layout.item_gov_detail, parent, false);
                bah = new GovDetailHolder(context, v);
                bah.setInternalClick(this);
            default:
                v = LayoutInflater.from(context).inflate(R.layout.item_gov_detail, parent, false);
                bah = new GovDetailHolder(context, v);
                bah.setInternalClick(this);
                break;
        }
        bah.setActivity(activity);
        bah.setFragment(fragment);
        bah.setPairs(pairs);
        return bah;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getDataType();
    }

    @Override
    public void onItemInternalClick(View itemView, View view, int position) {
        if (onItemInternalClick != null) {
            onItemInternalClick.onItemInternalClick(itemView, view, position);
        }
    }

    @Override
    public GovAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        this.onItemInternalClick = itemInternalClick;
        return this;
    }

}
